home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_apache2.idb / usr / freeware / apache2 / include / apr_thread_rwlock.h.z / apr_thread_rwlock.h
C/C++ Source or Header  |  2002-07-08  |  6KB  |  156 lines

  1. /* ====================================================================
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Apache" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  */
  54.  
  55. #ifndef APR_THREAD_RWLOCK_H
  56. #define APR_THREAD_RWLOCK_H
  57.  
  58. #include "apr.h"
  59. #include "apr_pools.h"
  60. #include "apr_errno.h"
  61.  
  62. #ifdef __cplusplus
  63. extern "C" {
  64. #endif /* __cplusplus */
  65.  
  66. #if APR_HAS_THREADS
  67.  
  68. /**
  69.  * @file apr_thread_rwlock.h
  70.  * @brief APR Thread RWLock Routines
  71.  */
  72.  
  73. /**
  74.  * @defgroup APR_ThreadRWLock Thread RWLock Routines
  75.  * @ingroup APR
  76.  * @{
  77.  */
  78.  
  79. typedef struct apr_thread_rwlock_t apr_thread_rwlock_t;
  80.  
  81. /**
  82.  * Create and initialize a read-write lock that can be used to synchronize
  83.  * threads.
  84.  * @param rwlock the memory address where the newly created readwrite lock
  85.  *        will be stored.
  86.  * @param pool the pool from which to allocate the mutex.
  87.  */
  88. APR_DECLARE(apr_status_t) apr_thread_rwlock_create(apr_thread_rwlock_t **rwlock,
  89.                                                    apr_pool_t *pool);
  90. /**
  91.  * Acquire a shared-read lock on the given read-write lock. This will allow
  92.  * multiple threads to enter the same critical section while they have acquired
  93.  * the read lock.
  94.  * @param rwlock the read-write lock on which to acquire the shared read.
  95.  */
  96. APR_DECLARE(apr_status_t) apr_thread_rwlock_rdlock(apr_thread_rwlock_t *rwlock);
  97.  
  98. /**
  99.  * Attempt to acquire the shread-read lock on the given read-write lock. This
  100.  * is the same as apr_thread_rwlock_rdlock(), only that the funtion fails
  101.  * if there is another thread holding the write lock, or if there are any
  102.  * write threads blocking on the lock. If the function failes for this case,
  103.  * APR_EBUSY will be returned. Note: it is important that the
  104.  * APR_STATUS_IS_EBUSY(s) macro be used to determine if the return value was
  105.  * APR_EBUSY, for portability reasons.
  106.  * @param rwlock the rwlock on which to attempt the shared read.
  107.  */
  108. APR_DECLARE(apr_status_t) apr_thread_rwlock_tryrdlock(apr_thread_rwlock_t *rwlock);
  109.  
  110. /**
  111.  * Acquire an exclusive-write lock on the given read-write lock. This will
  112.  * allow only one single thread to enter the critical sections. If there
  113.  * are any threads currently holding thee read-lock, this thread is put to
  114.  * sleep until it can have exclusive access to the lock.
  115.  * @param rwlock the read-write lock on which to acquire the exclusive write.
  116.  */
  117. APR_DECLARE(apr_status_t) apr_thread_rwlock_wrlock(apr_thread_rwlock_t *rwlock);
  118.  
  119. /**
  120.  * Attempt to acquire the exclusive-write lock on the given read-write lock. 
  121.  * This is the same as apr_thread_rwlock_wrlock(), only that the funtion fails
  122.  * if there is any other thread holding the lock (for reading or writing),
  123.  * in which case the function will return APR_EBUSY. Note: it is important
  124.  * that the APR_STATUS_IS_EBUSY(s) macro be used to determine if the return
  125.  * value was APR_EBUSY, for portability reasons.
  126.  * @param rwlock the rwlock on which to attempt the exclusive write.
  127.  */
  128. APR_DECLARE(apr_status_t) apr_thread_rwlock_trywrlock(apr_thread_rwlock_t *rwlock);
  129.  
  130. /**
  131.  * Release either the read or write lock currently held by the calling thread
  132.  * associated with the given read-write lock.
  133.  * @param rwlock the read-write lock rom which to release the lock.
  134.  */
  135. APR_DECLARE(apr_status_t) apr_thread_rwlock_unlock(apr_thread_rwlock_t *rwlock);
  136.  
  137. /**
  138.  * Destroy the read-write lock and free the associated memory.
  139.  * @param rwlock the rwlock to destroy.
  140.  */
  141. APR_DECLARE(apr_status_t) apr_thread_rwlock_destroy(apr_thread_rwlock_t *rwlock);
  142.  
  143. /**
  144.  * Get the pool used by this thread_rwlock.
  145.  * @return apr_pool_t the pool
  146.  */
  147. APR_POOL_DECLARE_ACCESSOR(thread_rwlock);
  148.  
  149. #endif  /* APR_HAS_THREADS */
  150.  
  151. #ifdef __cplusplus
  152. }
  153. #endif
  154.  
  155. #endif  /* ! APR_THREAD_RWLOCK_H */
  156.